package cinema.v1_0.service;

import cinema.v1_0.model.*;

import java.util.*;

public class CinemaService {
    /* 数组定长，简单演示 */
    private final User[]   users   = new User[100];
    private final Movie[]  movies  = new Movie[100];
    private final Hall[]   halls   = new Hall[10];
    private final Session[]sessions = new Session[200];

    private int userCount   = 0;
    private int movieCount  = 0;
    private int hallCount   = 0;
    private int sessionCount= 0;

    public CinemaService() {
        initData();
    }

    /* ---------- 初始化 ---------- */
    private void initData() {
        // 管理员
        users[userCount++] = new User("U001", "admin", "123456", "ADMIN", "13800000000");
        // 经理
        users[userCount++] = new User("U002", "manager1", "123456", "MANAGER", "13900000000");
        // 前台
        users[userCount++] = new User("U003", "front1", "123456", "FRONT", "13700000000");

        // 影厅
        halls[hallCount++] = new Hall("H001", "黄金厅", 8, 10);
        halls[hallCount++] = new Hall("H002", "白银厅", 10, 12);
        halls[hallCount++] = new Hall("H003", "翡翠厅", 7, 8);

        // 影片
        movies[movieCount++] = new Movie("M001", "泰坦尼克号",
                "詹姆斯·卡梅隆", "莱昂纳多 / 凯特",
                "爱情悲剧", 194, 9.5);
        movies[movieCount++] = new Movie("M002", "流浪地球",
                "郭帆", "吴京 / 屈楚萧",
                "科幻灾难", 125, 8.0);

        // 场次
        sessions[sessionCount++] = new Session("S001", "M001", "H001",
                "2025-08-20 19:30", 45.0);
        sessions[sessionCount++] = new Session("S002", "M002", "H002",
                "2025-08-20 20:00", 40.0);
    }

    /* ---------- 登录 ---------- */
    public boolean login(String name, String pwd) {
        for (int i = 0; i < userCount; i++) {
            if (users[i].getName().equals(name) && users[i].getPassword().equals(pwd)) {
                return true;
            }
        }
        return false;
    }

    public User[] listUsers()   { return Arrays.copyOf(users, userCount); }
    public Movie[] listMovies() { return Arrays.copyOf(movies, movieCount); }
    public Hall[] listHalls()   { return Arrays.copyOf(halls, hallCount); }
    public Session[] listSessions() { return Arrays.copyOf(sessions, sessionCount); }
}